icontheme: Refactor gtk_icon_theme_lookup_symbolic_colors()
authorBenjamin Otte <otte@redhat.com>
Mon, 30 Aug 2021 02:52:47 +0000 (04:52 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 30 Aug 2021 02:52:47 +0000 (04:52 +0200)
With the new enum, the code looks much cleaner.

gtk/gtkcssimageicontheme.c
gtk/gtkicontheme.c
gtk/gtkiconthemeprivate.h
gtk/gtkrendericon.c

index b9096b1006f588169a68d75fe0e4993b0a63822e..02e0c8a346142c3d05fbd4352656f123e6e9e496 100644 (file)
@@ -156,7 +156,7 @@ gtk_css_image_icon_theme_compute (GtkCssImage      *image,
   copy->icon_theme = gtk_icon_theme_get_for_display (display);
   copy->serial = gtk_icon_theme_get_serial (copy->icon_theme);
   copy->scale = gtk_style_provider_get_scale (provider);
-  gtk_icon_theme_lookup_symbolic_colors (style, &copy->colors[0], &copy->colors[3], &copy->colors[2], &copy->colors[1]);
+  gtk_icon_theme_lookup_symbolic_colors (style, copy->colors);
 
   return GTK_CSS_IMAGE (copy);
 }
index eb6b7285d371ff8f647046b9400752cad605d10a..91ea519a262bf8d5812157333b84d683fe6f5134 100644 (file)
@@ -2543,35 +2543,29 @@ gtk_icon_theme_error_quark (void)
 
 void
 gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
-                                       GdkRGBA     *color_out,
-                                       GdkRGBA     *success_out,
-                                       GdkRGBA     *warning_out,
-                                       GdkRGBA     *error_out)
+                                       GdkRGBA      color_out[4])
 {
   GtkCssValue *palette, *color;
+  const char *names[4] = {
+    [GTK_SYMBOLIC_COLOR_ERROR] = "error",
+    [GTK_SYMBOLIC_COLOR_WARNING] = "warning",
+    [GTK_SYMBOLIC_COLOR_SUCCESS] = "success"
+  };
   const GdkRGBA *lookup;
+  gsize i;
 
   color = style->core->color;
   palette = style->core->icon_palette;
-  *color_out = *gtk_css_color_value_get_rgba (color);
-
-  lookup = gtk_css_palette_value_get_color (palette, "success");
-  if (lookup)
-    *success_out = *lookup;
-  else
-    *success_out = *color_out;
-
-  lookup = gtk_css_palette_value_get_color (palette, "warning");
-  if (lookup)
-    *warning_out = *lookup;
-  else
-    *warning_out = *color_out;
+  color_out[GTK_SYMBOLIC_COLOR_FOREGROUND] = *gtk_css_color_value_get_rgba (color);
 
-  lookup = gtk_css_palette_value_get_color (palette, "error");
-  if (lookup)
-    *error_out = *lookup;
-  else
-    *error_out = *color_out;
+  for (i = 1; i < 4; i++)
+    {
+      lookup = gtk_css_palette_value_get_color (palette, names[i]);
+      if (lookup)
+        color_out[i] = *lookup;
+      else
+        color_out[i] = color_out[GTK_SYMBOLIC_COLOR_FOREGROUND];
+    }
 }
 
 
index bab1011d6938caa13a697ac282e86837b0b90a24..0d877332a356e40092dbaa4d0484d7347758aff3 100644 (file)
@@ -28,10 +28,7 @@ const char *gtk_string_set_add (GtkStringSet *set,
 #define IMAGE_MISSING_RESOURCE_PATH "/org/gtk/libgtk/icons/16x16/status/image-missing.png"
 
 void gtk_icon_theme_lookup_symbolic_colors   (GtkCssStyle      *style,
-                                              GdkRGBA          *color_out,
-                                              GdkRGBA          *success_out,
-                                              GdkRGBA          *warning_out,
-                                              GdkRGBA          *error_out);
+                                              GdkRGBA           color_out[4]);
 
 int gtk_icon_theme_get_serial (GtkIconTheme *self);
 
index 2cd601aa34683e78b4fa48b332487994bc51842e..a6c878491c4ea01ed4fe601a6baea72a17b81d84 100644 (file)
@@ -116,7 +116,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
   is_symbolic_paintable = GTK_IS_SYMBOLIC_PAINTABLE (paintable);
   if (is_symbolic_paintable)
     {
-      gtk_icon_theme_lookup_symbolic_colors (style, &colors[0], &colors[3], &colors[2], &colors[1]);
+      gtk_icon_theme_lookup_symbolic_colors (style, colors);
 
       if (gdk_rgba_is_clear (&colors[0]))
         goto transparent;